package com.landeb.shop.huo.act;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.widget.LinearLayout;

import com.landeb.shop.R;
import com.landeb.shop.huo.adapter.ActOrderTabVPAdapter;
import com.landeb.shop.huo.frag.OrderFragment;
import com.landeb.shop.huo.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

public class MyOrderActivity extends BaseActivity implements View.OnClickListener {

    private LinearLayout btnBack;
    private TabLayout mTabLayout;
    private NoScrollViewPager mViewPager;

    private List<String> mTabs;
    private List<OrderFragment> mFragments;
    private ActOrderTabVPAdapter mAdapter;

    private int mPage = 0;

    public static final int QUANBU=0;
    public static final int DAIFUKUAN=1;
    public static final int DAIFAHUO=2;
    public static final int DAISHOUHUO=3;
    public static final int DAIPINGJIA=4;



    public static void toAct(Context context) {
        Intent intent = new Intent(context, MyOrderActivity.class);
        context.startActivity(intent);
    }

    public static void toAct(Context context, int page) {
        Intent intent = new Intent(context, MyOrderActivity.class);
        intent.putExtra("page", page);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);

        Intent intent = getIntent();

        mPage = intent.getIntExtra("page", 0);

        initView();
        initData();
        initEvent();

    }

    private void initEvent() {

        btnBack.setOnClickListener(this);

        mViewPager.setCurrentItem(mPage);

    }

    private void initData() {

        mTabs = new ArrayList<>();
        mTabs.add("全部");
        mTabs.add("待付款");
        mTabs.add("待发货");
        mTabs.add("待收货");
        mTabs.add("待评价");

        OrderFragment allOrders = OrderFragment.newInstance("", null, null);
        OrderFragment toPayOrders = OrderFragment.newInstance("", "unpay", null);
        OrderFragment toSendOrders = OrderFragment.newInstance("", "pay", null);
        OrderFragment toReceiveOrders = OrderFragment.newInstance("", "send", null);
        OrderFragment toRatedOrders = OrderFragment.newInstance("", "finish", "2");

        mFragments = new ArrayList<>();
        mFragments.add(allOrders);
        mFragments.add(toPayOrders);
        mFragments.add(toSendOrders);
        mFragments.add(toReceiveOrders);
        mFragments.add(toRatedOrders);

        mViewPager.setOffscreenPageLimit(4);
        mAdapter = new ActOrderTabVPAdapter(getSupportFragmentManager(), mTabs, mFragments);
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setupWithViewPager(mViewPager);

    }

    private void initView() {

        btnBack = (LinearLayout) findViewById(R.id.act_order_btn_back);
        mTabLayout = (TabLayout) findViewById(R.id.act_order_tab);
        mViewPager = (NoScrollViewPager) findViewById(R.id.act_order_viewpager);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.act_order_btn_back:
                // TODO: 2016/11/23 返回键
                onBackPressed();
                break;
        }

    }
}
